@using BlazorApp.Pages.Common.Html
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using BlazorApp.Pages.Event
@using k8s.Models
@using Mapster
@inherits BlazorApp.Pages.Common.DrawerPageBase<k8s.Models.V1Role>
@if (Role != null)
{
    <RoleAction Item="Role" MenuMode="MenuMode.Horizontal"></RoleAction>
    <Divider Orientation="left" Style="font-weight:bold">@L["Metadata"]</Divider>
    <MetadataView Item="Role.Metadata" ExplainFieldPrefix="role"></MetadataView>
    <Divider Orientation="left" Style="font-weight:bold">@L["Spec"]</Divider>

    <HTable Bordered Column="1">

        @if (Role.Rules is { Count: > 0 })
        {
            <HTableColumn Title=@L["Rules"] ExplainField="role.rules">
                @foreach (var rule in Role.Rules)
                {
                    <HTable>
                        <PropertyListView Items="rule.ResourceNames" T="string" Title=@L["ResourceNames"]
                                          ExplainField="role.rules.resourceNames">
                        </PropertyListView>
                        <PropertyListView Items="rule.NonResourceURLs" T="string" Title=@L["NonResourceURLs"]
                                          ExplainField="role.rules.nonResourceURLs">
                        </PropertyListView>
                        <PropertyListView Items="rule.ApiGroups" T="string" Title=@L["ApiGroups"]
                                          ExplainField="role.rules.apiGroups">
                        </PropertyListView>
                        <PropertyListView Items="rule.Resources" T="string" Title=@L["Resources"]
                                          ExplainField="role.rules.resources">
                        </PropertyListView>
                        <PropertyListView Items="rule.Verbs" T="string" Title=@L["Verbs"]
                                          ExplainField="role.rules.verbs">
                        </PropertyListView>
                    </HTable>
                }
            </HTableColumn>
        }
    </HTable>
    @if (Subjects is { Count: > 0 })
    {
        <Divider Orientation="left" Style="font-weight:bold">@L["Had Subjects"]</Divider>
        <HTable>

            @foreach (var subject in Subjects)
            {
                <HTableColumn Title=@L["Kind"]>
                    <RefView FullView="true" Ref="subject.Adapt<V1ObjectReference>()"></RefView>
                </HTableColumn>
            }

        </HTable>
    }

    <MiniEventListView Uid="@Role.Metadata.Uid"></MiniEventListView>
}
